/**
 * Created by wangxin on 2017-9-26 10:02:01.
 */

'use strict';
const page = {
    url : {
        getRecord:contextData.contextPath+'/work/getRecord',
        changeRecord:contextData.contextPath+'/work/changeRecord'
    },
    _id : null,
    list : null,
};

page.init = function () {
    page.initElement();
    page.initEvent();
};

page.initElement = function () {
    const thisPage = this;

};

page.initEvent = function () {
    const thisPage = this;

    Dolphin.ajax({
        url:thisPage.url.getRecord,
        data:{openId:contextData.userData.openid,eventId:contextData.data.eventId},
        onSuccess:function (data) {
            console.log(data);
            new Vue({
                el: '#container',
                data:{
                    records: data.record
                },
                methods:{
                    changeRecord:function (id) {
                        $.confirm("该操作请让店员操作，自己操作则奖品无效哦","确认领奖?", function() {
                            Dolphin.ajax({
                                url:thisPage.url.changeRecord,
                                data:{_id:id},
                                onSuccess:function (data) {
                                    setTimeout(function () {
                                        location.reload();
                                    },1000)
                                }
                            })
                        }, function() {
                            //点击取消后的回调函数
                        });
                    }
                }
            });

        },
        onError: function (e) {
            alert('网络出错啦，为您重新加载');
        }
    });



};

function formatterDate(val, formatter) {
    if(val){
        var date = Dolphin.string2date(val, "yyyy-MM-ddThh:mm:ss.");
        date.setHours(date.getHours() + 8);
        return Dolphin.date2string(date, formatter || "yyyy-MM-dd");
    }else{
        return '';
    }
}

$(function () {
    page.init();
});


